<?php

require_once('../config.php');

$imageId = intval($_GET['imageId']);
$colorApplicationId = empty($_GET['colorApplicationId']) ? 0 : intval($_GET['colorApplicationId']);

if(($imageId > 0) && ($colorApplicationId > 0)) {

	require_once(WSB_MODULES_PATH .'sherpa/models/ImageGateway.php');

	$gateway = new Sherpa_Model_ImageGateway();
	$gateway->setUseModels(true);
	$variant = $gateway->fetchImageVariant($imageId, $colorApplicationId);
	if($variant->isLoaded()) {
		header('Content-type: application/json');
		echo $variant->toJson();
		exit;
	}

}

if(($imageId > 0)) {

	require_once(WSB_MODULES_PATH .'sherpa/models/ImageGateway.php');

	$gateway = new Sherpa_Model_ImageGateway();
	$gateway->setUseModels(true);
	$image = $gateway->fetchImage($imageId);
	if(!$image->isEmpty()) {
		header('Content-type: application/json');
		echo $image->toJson();
		exit;
	}

}

header( 'HTTP/1.1 404 Not Found' );
